import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class GameWindowAWT extends Frame
{
	private static final long serialVersionUID = 1L;
	private static BoardAWT board = new BoardAWT();
	private TitlePanelAWT title = new TitlePanelAWT();
	private OptionsPanelAWT options = new OptionsPanelAWT();
	private MenuBar menubar = new MenuBar();
	
	/**@return reference to the game board**/
	public static BoardAWT getBoard() 
	{
		return board;
	}

	/**class constructor**/
	public GameWindowAWT()
	{
		this.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
		Menu gamemenu = new Menu("Game");
		MenuItem single = new MenuItem("Single Player");
		single.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				board.setMode(1);
				board.init();
				//System.out.print("single player");
			}
		});
		gamemenu.add(single);
		MenuItem multi = new MenuItem("2 Players");
		multi.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				board.setMode(2);
				board.init();
				//System.out.print("multiplayer");
			}
		});
		gamemenu.add(multi);
		menubar.add(gamemenu);
		Menu exitmenu = new Menu("Exit");
		MenuItem exititem = new MenuItem("Bye bye");
		exitmenu.add(exititem);
		exititem.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.exit(0);
				//System.out.print("exit");
			}
		});
		menubar.add(exitmenu);
		this.setMenuBar(menubar);
		this.setBackground(Color.BLACK);
		this.setTitle("FourInARow");
		this.setResizable(false);
		this.setLayout(null);
		title.setBounds(0, 50, 640, 50);
		this.add(title);//,BorderLayout.NORTH);
		setLayout(new BorderLayout());
		this.add(board,BorderLayout.CENTER);
		this.add(options,BorderLayout.SOUTH);
		try 
		{
			BufferedImage icon = ImageIO.read(new File("res\\icon2.png"));
			this.setIconImage(icon);
		} 
		catch (IOException e1) {}
	}
	
	/**main method**/
	public static void main(String[] args)
	{
		GameWindowAWT window = new GameWindowAWT();
		window.setBounds(0, 0, 640, 510);
		window.setVisible(true);
	}
	
}
